package com.hxb.example.api;

import com.hxb.example.model.ReturnT;
import com.hxb.example.model.TriggerParam;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;

public interface XxlJobTriggerClient {

    @PostMapping
    ReturnT<String> triggerJob(@RequestHeader("token") String token, @RequestBody TriggerParam triggerParam);

    @Component
    public static class XxlJobTriggerClientFallback implements FallbackFactory<XxlJobTriggerClient> {
        @Override
        public XxlJobTriggerClient create(Throwable cause) {
            return new XxlJobTriggerClient() {
                @Override
                public ReturnT<String> triggerJob(String token, TriggerParam triggerParam) {
                    return ReturnT.FAIL;
                }
            }
        }
    }
}
